package com.itfreer.gis.server.vector.generate.pipeline;

import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.simplify.DouglasPeuckerSimplifier;
import org.locationtech.jts.simplify.TopologyPreservingSimplifier;

import com.itfreer.gis.server.vector.generate.Pipeline;

/**
 * 简化Geometry
 */
public class Simplify extends Pipeline {

	private final double distanceTolerance;

	public Simplify(double distanceTolerance) {
		this.distanceTolerance = distanceTolerance;
	}

	@Override
	protected Geometry _run(Geometry geom) throws Exception {
		switch (geom.getDimension()) {
		case 2:
			return TopologyPreservingSimplifier.simplify(geom, this.distanceTolerance);
		case 1:
			return DouglasPeuckerSimplifier.simplify(geom, this.distanceTolerance);
		default:
			return geom;
		}
	}
}